home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / Printer / src / Xerox_4020 / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.8 KB  |  136 lines

  1. /*
  2.     Transfer routine for Xerox_4020 driver.
  3.     David Berezowski - October/87.
  4.  
  5.   Copyright (c) 1988 Commodore-Amiga, Inc.
  6.  
  7.   Executables based on this information may be used in software
  8.   for Commodore Amiga computers.  All other rights reserved.
  9.  
  10.   This information is provided "as is"; no warranties are made.
  11.   All use is at your own risk, and no liability or responsibility is assumed.
  12. */
  13.  
  14.  
  15. #include <exec/types.h>
  16. #include "../printer/printer.h"
  17. #include "../printer/prtbase.h"
  18. #include "../printer/prtgfx.h"
  19.  
  20. Transfer(PInfo, y, ptr, colors)
  21. struct PrtInfo *PInfo;
  22. UWORD y;    /* row # */
  23. UBYTE *ptr;    /* ptr to buffer */
  24. UWORD *colors; /* indexes to color buffers */
  25. {
  26.     extern struct PrinterData *PD;
  27.  
  28.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  29.     UBYTE *dmatrix, *bptr, *yptr, *mptr, *cptr;
  30.     UBYTE dvalue, Black, Yellow, Magenta, Cyan, threshold;
  31.     UBYTE bit, y3;
  32.     union colorEntry *ColorInt;
  33.     UWORD x, x3, width, sx, *sxptr;
  34.  
  35.     /* pre-compute */
  36.     /* printer specific */
  37.     y3 = y & 3;
  38.     bptr = ptr + colors[y3];
  39.     yptr = ptr + colors[4 + y3];
  40.     mptr = ptr + colors[8 + y3];
  41.     cptr = ptr + colors[12 + y3];
  42.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  43.     x = PInfo->pi_xpos; /* get starting x position */
  44.     ColorInt = PInfo->pi_ColorInt; /* get ptr to color intensities */
  45.     sxptr = PInfo->pi_ScaleX;
  46.     width = PInfo->pi_width; /* get # of source pixels */
  47.  
  48.     /* pre-compute threshold; are we thresholding? */
  49.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  50.         dvalue = threshold ^ 15; /* yes, so pre-compute dither value */
  51.         do { /* for all source pixels */
  52.             /* pre-compute intensity values for Black component */
  53.             Black = ColorInt->colorByte[PCMBLACK];
  54.             ColorInt++; /* bump ptr for next time */
  55.  
  56.             sx = *sxptr++;
  57.  
  58.             do { /* use this pixel 'sx' times */
  59.                 /* if should render black */
  60.                 if (Black > dvalue) {
  61.                     /* set bit in black buffer */
  62.                     *(bptr + (x >> 3)) |= bit_table[x & 7];
  63.                 }
  64.                 ++x; /* done 1 more printer pixel */
  65.             } while (--sx);
  66.         } while (--width);
  67.     }
  68.     else { /* not thresholding, pre-compute ptr to dither matrix */
  69.         dmatrix = PInfo->pi_dmatrix + (y3 << 2);
  70.         if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) {
  71.             do { /* for all source pixels */
  72.                 /* pre-compute intensity values for Black */
  73.                 Black = ColorInt->colorByte[PCMBLACK];
  74.                 ColorInt++; /* bump ptr for next time */
  75.  
  76.                 sx = *sxptr++;
  77.  
  78.                 do { /* use this pixel 'sx' times */
  79.                     /* if should render black */
  80.                     if (Black > dmatrix[x & 3]) {
  81.                         /* set bit in black buffer */
  82.                         *(bptr + (x >> 3)) |=
  83.                             bit_table[x & 7];
  84.                     }
  85.                     ++x; /* done 1 more printer pixel */
  86.                 } while (--sx);
  87.             } while (--width);
  88.         }
  89.         else { /* color */
  90.             do { /* for all source pixels */
  91.                 /* pre-compute intensity vals for each color */
  92.                 Black = ColorInt->colorByte[PCMBLACK];
  93.                 Yellow = ColorInt->colorByte[PCMYELLOW];
  94.                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  95.                 Cyan = ColorInt->colorByte[PCMCYAN];
  96.                 ColorInt++; /* bump ptr for next time */
  97.  
  98.                 sx = *sxptr++;
  99.  
  100.                 do { /* use this pixel 'sx' times */
  101.                     /* pre-compute 'byte to set' value */
  102.                     x3 = x >> 3;
  103.                     /* pre-compute 'bit to set' val */
  104.                     bit = bit_table[x & 7];
  105.                     /* pre-compute dither value */
  106.                     dvalue = dmatrix[x & 3];
  107.                     /* if should render black */
  108.                     if (Black > dvalue) {
  109.                         /* set bit in black buffer */
  110.                         *(bptr + x3) |= bit;
  111.                     }
  112.                     /* black not rendered, check color */
  113.                     else  {
  114.                         /* if should render yellow */
  115.                         if (Yellow > dvalue) {
  116.                             /* set bit in Y buf */
  117.                             *(yptr + x3) |= bit;
  118.                         }
  119.                         /* if should render magenta */
  120.                         if (Magenta > dvalue) {
  121.                             /* set bit in M buf */
  122.                             *(mptr + x3) |= bit;
  123.                         }
  124.                         /* if should render cyan */
  125.                         if (Cyan > dvalue) {
  126.                             /* set bit in C buf */
  127.                             *(cptr + x3) |= bit;
  128.                         }
  129.                     }
  130.                     ++x; /* done 1 more printer pixel */
  131.                 } while (--sx);
  132.             } while (--width);
  133.         }
  134.     }
  135. }
  136.